<?php
/**
 * Created by IntelliJ IDEA.
 * User: jimmyhsu
 * Date: 2017/5/14
 * Time: 01:24
 */
include('checkLogin.php');
$course_id = $_GET['course_id'];
$f_id = $_GET['f_id'];
$sql = "select type from sharedfile where course_id='$course_id' and f_id=$f_id";
if ($query = mysqli_query($cn, $sql)) {
    $row = mysqli_fetch_array($query);
    $file_name = $f_id . '.' . $row['type'];
    $dir = 'file/' . $course_id . '/' . $file_name;
    if (file_exists($dir)) {
        unlink($dir);
        $sql = "delete from sharedfile where course_id='$course_id' and f_id=$f_id";
        mysqli_query($cn, $sql);
        echo "success";
    } else {
        echo "file_not_exists";
    }
}


